//
//  WalletCenterView.m
//  NiuBanJin
//
//  Created by Billy on 15/10/17.
//  Copyright © 2015年 zzjr. All rights reserved.
//

#import "WalletCenterView.h"

@implementation WalletCenterView

- (instancetype)initWithFrame:(CGRect)frame title:(NSString *)title rate:(NSString *)number isRateAdding:(NSNumber *)adding isEnabledRightCornerICon:(NSNumber *)rightCornerICon {
    
    self = [super initWithFrame:frame];
    
    if (self) { //如果属性再多一点，你也用这个方法？？？不考虑kvo?
        
        self.str_promptText = title;
        self.str_shownValue = number;
        self.isEnabeldRightCornerIcon = rightCornerICon;
        self.isRateAdding = adding;
        [self setBackgroundColor:BASECOLOR];
        [self configureView];
    }
    
    return self;
}

- (void) configureView {
    
    //1. 添加手势
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(viewTaped:)];
    [self addGestureRecognizer:tap];
    
    //2. subivews
    
    //a. 小黑框
    
    UIView *view_tmp = [UsefulUtil viewCreationWithFrame:CGRectMake(MULTIPLYWIDTH(40.0/2), MULTIPLYHEIGHT(50.0/2), MULTIPLYWIDTH(10.0/2), MULTIPLYHEIGHT(10.0/2)) backgroundColor:[UsefulUtil colorWithHexString:@"#9d9d9d"] backGroundImage:nil];
    
    [self addSubview:view_tmp];
    
    //b.label (提示 和 显示具体数值)
    
    UILabel *label_ratePromt = [UsefulUtil labelCreationWithFrame:CGRectMake(CGRectGetMaxX(view_tmp.frame) + MULTIPLYWIDTH(20.0/2), MULTIPLYHEIGHT(40.0/2),self.bounds.size.width - MULTIPLYWIDTH(60.0/2), MULTIPLYHEIGHT(30.0/2)) textColor:[UsefulUtil colorWithHexString:@"#434343"] fontName:[UIFont systemFontOfSize:16.0] text:self.str_promptText];
    
    [self addSubview:label_ratePromt];
    
    UILabel *label_shown = [UsefulUtil labelCreationWithFrame:CGRectMake(MULTIPLYWIDTH(70.0/2), CGRectGetMaxY(label_ratePromt.frame) + MULTIPLYHEIGHT(35.0/2), MULTIPLYWIDTH(160.0/2), MULTIPLYHEIGHT(60.0/2)) textColor:REDCOLOR fontName:[UIFont systemFontOfSize:30.0] text:self.str_shownValue];
    
    // 添加属性 8%+1% ，考虑到数据变化性，属性设置放在真正获得数据的时候
    
    [label_shown setTag:11]; //显示年化收益
    [self addSubview:label_shown];
    
    //c. 加息图标
    
    if ([self.isRateAdding boolValue]) { //按具体情况显示
        
        UIImageView *imageView_tmp = [[UIImageView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(label_shown.frame) +MULTIPLYWIDTH(22.0/2),  MULTIPLYHEIGHT( 90.0/2), MULTIPLYWIDTH(50.0/2), MULTIPLYHEIGHT(66.0/2))];
        
        [imageView_tmp setImage:[UIImage imageNamed:@"up-fire"]];
        [self addSubview:imageView_tmp];
    }
    
    // 右下角icon
    
    if ([self.isEnabeldRightCornerIcon boolValue]) {
        
        UIImageView *imageView_tmp = [UsefulUtil imageViewCreationWithFrame:CGRectMake(self.bounds.size.width - MULTIPLYWIDTH(20.0/2), self.bounds.size.height - MULTIPLYHEIGHT(20.0/2), MULTIPLYWIDTH(20.0/2), MULTIPLYHEIGHT(20.0/2)) image:[UIImage imageNamed:@"lowRightCorner"]];
        
        [self addSubview:imageView_tmp];
    }
}

- (void)drawRect:(CGRect)rect {
    
    
}

- (void) viewTaped: (UITapGestureRecognizer *) tap {
    
    [self.delegate tapGestureHandle:tap];
}



@end
